/**
 * @param {number[][]} matrix
 * @return {void} Do not return anything, modify matrix in-place instead.
 * 输入：matrix = [[1,2,3],[4,5,6],[7,8,9]]
输出：[[7,4,1],[8,5,2],[9,6,3]]
 */
var rotate = function (matrix) {
  let index = 0
  const len = matrix.length - 1
  while (index <= len) {
    let data = []
    for (let i = 0; i <= len; i++) {
      let delData = matrix[i].splice(0, 1)
      data.unshift(delData[0])
    }
    matrix.push(data)
    index++
  }
  for (let j = 0; j <= len; j++) {
    matrix.splice(0, 1)
  }
  return matrix
}

console.log(
  rotate([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
  ])
)
